<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Handlers\WeconHandler;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class DedustingAlarmLog extends Model
{
    const STATUS_YES = 1;
    const STATUS_NO = 0;
    const STATUS_TEXT = ['0' => '未处理', '1' => '已处理'];
    protected $fillable = ['device_id', 'point', 'alarm_id', 'alarm_name','alarm_level', 'alarm_value', 'library_id', 'real_value'];

    
    protected $table = 'xfy_dedusting_alarm_logs';

    public function device()
    {
        return $this->belongsTo(DedustingDevice::class);
    }

    public function library()
    {
        return $this->hasOne(DedustingLibrary::class, 'id', 'library_id');
    }

    public function admin()
    {
        return $this->hasOne(AdminUser::class, 'id', 'operator');
    }

    public static function makeAlarmPush()
    {
        # code...
    }

    protected static function judge($cond, $realVal, $presetVal){
        switch ($cond) {
            case '>':
                return $realVal > $presetVal;
                break;
            case '<':
                return $realVal < $presetVal;
                break;
            case '>=':
                return $realVal >= $presetVal;
                break;
            case '<=':
                return $realVal <= $presetVal;
                break;
            case '=':
                return $realVal = $presetVal;
                break;
            default:
                break;
        }
    }
}